1 00:00:00,260 --> 00:00:05,900 In this lecture, we're going to take a quick look at proximity prompts, which are basically billboard 2 00:00:05,900 --> 00:00:09,920 guy buttons that you can interact with to trigger an event in the prompt. 3 00:00:09,920 --> 00:00:15,560 Proximity prompts only appear on the screen once a player gets close enough to one, based on one of 4 00:00:15,560 --> 00:00:19,130 its properties, called Max activation distance. 5 00:00:19,130 --> 00:00:25,760 We can place proximity prompts inside of parts, and the prompt will appear at the origin of a particular 6 00:00:25,760 --> 00:00:26,330 part. 7 00:00:26,330 --> 00:00:32,240 Or, if we would like to be able to change the positioning of a proximity prompt within a part, then 8 00:00:32,240 --> 00:00:37,250 we can also use attachments and the prompt will appear at the position of the attachment. 9 00:00:37,250 --> 00:00:40,910 So I can add a proximity prompt to this part. 10 00:00:40,910 --> 00:00:47,570 And for demonstration purposes I'm also going to add one over here inside of this attachment. 11 00:00:48,330 --> 00:00:52,320 And then I'm going to add another proximity prompt inside of this part. 12 00:00:53,480 --> 00:00:59,060 And for this one I'm going to keep requires line of sight enabled. 13 00:00:59,060 --> 00:01:02,390 And then for the other ones I'm going to disable that property. 14 00:01:02,390 --> 00:01:08,480 And this property basically determines whether or not we can see the proximity prompt appear through 15 00:01:08,480 --> 00:01:09,320 walls. 16 00:01:09,950 --> 00:01:14,720 And as you can see when I play test the Game, here's our first proximity prompt that is inside of the 17 00:01:14,720 --> 00:01:16,130 center of this part. 18 00:01:16,130 --> 00:01:21,320 My other proximity prompt is right over here inside of the attachment, and then my other proximity 19 00:01:21,320 --> 00:01:24,260 prompt is over here inside of this part. 20 00:01:24,440 --> 00:01:28,730 Now I'm not able to see that other one over on this other side of the part. 21 00:01:28,730 --> 00:01:31,910 And that's because the max activation distance is not large enough. 22 00:01:31,910 --> 00:01:38,990 So let me go ahead and select it and increase its max activation distance to let's say 30 studs. 23 00:01:39,110 --> 00:01:44,000 So now we should be able to or actually okay. 24 00:01:44,000 --> 00:01:44,150 Yeah. 25 00:01:44,150 --> 00:01:46,280 This is the one that requires line of sight. 26 00:01:46,280 --> 00:01:48,050 My bad I have that one mistaken. 27 00:01:48,050 --> 00:01:53,090 So once I can no longer see the part because it's blocking my view with this other part, as you can 28 00:01:53,090 --> 00:01:54,140 see, it disappears. 29 00:01:54,140 --> 00:01:57,650 It isn't until I regain sight that it will reappear. 30 00:01:58,450 --> 00:02:04,990 And then for these other prompts inside of this part, let me go ahead and increase the max activation 31 00:02:04,990 --> 00:02:05,950 distance. 32 00:02:05,950 --> 00:02:11,980 Even if I'm behind this other part here, I'm still able to see those other proximity prompts. 33 00:02:12,610 --> 00:02:16,510 So let's go ahead and take a look at the different properties inside of a proximity prompt. 34 00:02:16,510 --> 00:02:21,790 One would be the action text, and this is going to be the text that appears inside of the proximity 35 00:02:21,790 --> 00:02:27,160 prompt, basically telling them what the action is or what's going to happen when they trigger this 36 00:02:27,160 --> 00:02:27,550 prompt. 37 00:02:27,550 --> 00:02:30,160 By default, it's just set to a string of interact. 38 00:02:30,160 --> 00:02:32,860 But you can place any text inside of here that you want. 39 00:02:32,860 --> 00:02:39,190 For example, you can change the action text to maybe um, trigger bomb or something like that if it's 40 00:02:39,190 --> 00:02:39,850 a bomb. 41 00:02:40,470 --> 00:02:45,390 The next property here is called clickable prompt, and this just determines whether or not a player 42 00:02:45,390 --> 00:02:51,240 on PC is able to use their mouse button to hold down and interact with the proximity prompt. 43 00:02:51,240 --> 00:02:56,820 If you disable this, then the only way for the player to interact or trigger the proximity prompt would 44 00:02:56,820 --> 00:02:59,610 have to be using the Keycode. 45 00:02:59,610 --> 00:03:05,160 That's determined by the keyboard Keycode property, so they have to hold down E on their keyboard. 46 00:03:05,430 --> 00:03:07,920 The enable property is very self-explanatory. 47 00:03:07,920 --> 00:03:11,760 If you disable it, the proximity prompt will disappear and it will no longer work. 48 00:03:11,760 --> 00:03:15,240 But if you re-enable it, then it will display back on the screen. 49 00:03:15,240 --> 00:03:19,110 If the player is close enough with it and the player can interact with it. 50 00:03:19,110 --> 00:03:25,500 This property, called exclusivity, is specifically for determining how proximity prompts will display. 51 00:03:25,500 --> 00:03:32,220 So for example, if you set it to one per button, what is going to happen is that only one prompt will 52 00:03:32,220 --> 00:03:36,240 appear on the player's screen based on the keycode. 53 00:03:36,240 --> 00:03:42,090 So if you had a proximity prompt with a keycode of E and another one with the keycode of Q, both of 54 00:03:42,090 --> 00:03:46,110 them would appear on the screen if both were set to the one per button enum. 55 00:03:46,110 --> 00:03:52,380 But if, let's say both had the keyboard keycode of E, then only one of them is going to show at a 56 00:03:52,380 --> 00:03:53,040 time. 57 00:03:53,040 --> 00:03:59,250 If you set it to one globally, then it will only display one proximity prompt at a time, no matter 58 00:03:59,250 --> 00:03:59,610 what. 59 00:03:59,610 --> 00:04:05,010 And then the last one is going to be always show, which allows the proximity prompt to appear on the 60 00:04:05,010 --> 00:04:05,670 screen. 61 00:04:05,670 --> 00:04:10,380 No matter if there is other proximity prompts around it, it will always show on the screen once the 62 00:04:10,380 --> 00:04:12,270 player gets close enough to it. 63 00:04:12,270 --> 00:04:18,390 We have the ability to change what Keycode needs to be pressed down on a gamepad or a controller. 64 00:04:18,390 --> 00:04:21,420 For console players, we can determine the whole duration. 65 00:04:21,420 --> 00:04:24,210 So how long do you have to hold it to trigger the prompt? 66 00:04:24,210 --> 00:04:28,290 We can change the keyboard keycode to a whole bunch of other different keys. 67 00:04:28,290 --> 00:04:30,660 I believe the default is always going to be E. 68 00:04:30,810 --> 00:04:35,310 We can change how far away the player can interact with the proximity prompt. 69 00:04:35,310 --> 00:04:41,010 With the max activation distance, we can set something called the object text inside of the proximity 70 00:04:41,010 --> 00:04:44,340 prompt, which is just another little extra description that you can give it. 71 00:04:44,340 --> 00:04:47,880 For this one, I'll just give it a example. 72 00:04:47,880 --> 00:04:49,890 Object text string. 73 00:04:50,220 --> 00:04:54,660 We are able to change this property requires a line of sight, which I explained earlier. 74 00:04:54,660 --> 00:04:59,430 Basically, if you can see the proximity prompt through other parts, or if it should disappear when 75 00:04:59,430 --> 00:05:00,600 you can no longer see it. 76 00:05:01,020 --> 00:05:06,750 The style enum basically allows you just to change it from default to custom, and then you can check 77 00:05:06,750 --> 00:05:12,840 this style property, check to see if it's custom, and then you would write your own script to display 78 00:05:12,840 --> 00:05:14,550 a custom proximity prompt. 79 00:05:14,550 --> 00:05:19,320 So this is for if you don't like Roblox's default implementation with proximity prompts and you want 80 00:05:19,320 --> 00:05:25,140 to make your own custom UI, you would set the style to custom, which would disable the default behavior 81 00:05:25,140 --> 00:05:28,020 for the proximity prompt, or it won't show the default UI. 82 00:05:28,020 --> 00:05:33,990 And then that's where you can script your own GUI or UI for the proximity prompt. 83 00:05:34,470 --> 00:05:42,660 And then UI offset is for offsetting the prompts UI in pixels on the x and the y axes. 84 00:05:42,660 --> 00:05:45,900 So let's go ahead and set the whole duration to let's say three seconds. 85 00:05:45,930 --> 00:05:49,290 Let's change the keyboard key code to. 86 00:05:49,290 --> 00:05:55,170 Let's say let's do C, we'll keep the max activation distance at ten. 87 00:05:56,250 --> 00:05:59,940 We'll have this object text, this action text. 88 00:05:59,940 --> 00:06:02,940 And then we have clickable prompt disabled. 89 00:06:02,940 --> 00:06:04,560 So I'll actually show you what that does. 90 00:06:04,560 --> 00:06:06,120 Let me play test the game. 91 00:06:06,390 --> 00:06:08,010 And then I can go over here. 92 00:06:08,010 --> 00:06:10,140 There is my action text trigger bomb. 93 00:06:10,140 --> 00:06:11,670 And then there's my object text. 94 00:06:11,670 --> 00:06:15,120 So example object text I have to press C on my keyboard. 95 00:06:15,120 --> 00:06:19,890 And if I click with my mouse button I'm unable to interact with this proximity prompt. 96 00:06:19,890 --> 00:06:25,110 However, with this other one, I am able to click on it to interact with the proximity prompt. 97 00:06:25,110 --> 00:06:31,230 For this one I have to hold down C, and there it fills in for a total of three seconds and then it 98 00:06:31,230 --> 00:06:34,710 triggers the prompt, but I'm not able to click on it. 99 00:06:35,320 --> 00:06:39,670 Now there are several events we can listen to inside of our proximity prompts. 100 00:06:39,670 --> 00:06:44,410 So I'm just inside of a local script and I'm going to make a reference to my prompt, which is in the 101 00:06:44,410 --> 00:06:45,550 workspace. 102 00:06:45,550 --> 00:06:47,200 I'll get my part. 103 00:06:47,200 --> 00:06:51,490 Let me rename it to Proximity Part. 104 00:06:52,440 --> 00:06:57,870 So I'll get my proximity part, and then I'll refer to the attachment and I'll just grab the proximity 105 00:06:57,870 --> 00:06:58,890 prompt in that one. 106 00:06:58,890 --> 00:07:04,290 And then let me make sure that streaming is disabled so I don't have to use wait for child. 107 00:07:04,620 --> 00:07:10,200 And now inside of my prompt I have access to several events which are listed right here. 108 00:07:10,200 --> 00:07:13,620 For example, we can listen for when the prompt is triggered. 109 00:07:13,620 --> 00:07:19,200 So it says triggered when the prompt key button is pressed, or after a specified amount of time. 110 00:07:19,560 --> 00:07:25,800 Um, for holding the button we have some other events such as prompt button hold began and says triggered 111 00:07:25,800 --> 00:07:31,530 when a player begins holding down connected to a prompt with a non-zero hold duration. 112 00:07:31,530 --> 00:07:36,510 So this is specifically for any proximity prompts whose hold duration is greater than zero. 113 00:07:36,510 --> 00:07:38,190 And then we also have one. 114 00:07:38,190 --> 00:07:39,570 Actually let me type out prompt. 115 00:07:39,570 --> 00:07:42,030 We have one for when the hold begins. 116 00:07:42,030 --> 00:07:43,980 We have one for when the hold ends. 117 00:07:43,980 --> 00:07:46,140 And then we have two other events here. 118 00:07:46,140 --> 00:07:48,630 And this is specifically for the client. 119 00:07:48,630 --> 00:07:54,240 So this will tell us when the prompt has been displayed on the screen on the client, and when the prompt 120 00:07:54,240 --> 00:07:56,520 has become hidden on the client. 121 00:07:56,520 --> 00:07:58,140 These are client only events. 122 00:07:58,140 --> 00:08:00,090 You can't use these on the server. 123 00:08:00,510 --> 00:08:02,490 So let's go ahead and listen to all of these events. 124 00:08:02,490 --> 00:08:05,250 I'll just connect a function to each one of them. 125 00:08:05,250 --> 00:08:10,050 It'll also tell us the player who triggered or who is holding down the current button. 126 00:08:10,050 --> 00:08:11,790 So we'll just print out their name. 127 00:08:11,790 --> 00:08:17,040 Let me make a parameter for that player, and then we'll just print out the player's name. 128 00:08:17,910 --> 00:08:21,390 We'll do the same thing for when the hold ends. 129 00:08:21,390 --> 00:08:25,530 So hold and we'll print player name. 130 00:08:26,010 --> 00:08:28,140 And actually let's go ahead and insert an extra string. 131 00:08:28,140 --> 00:08:30,300 So we'll call this one start. 132 00:08:30,420 --> 00:08:34,410 Concatenate it with the player name and then we'll just copy that. 133 00:08:34,410 --> 00:08:37,230 Do the same thing here but we'll say end. 134 00:08:37,710 --> 00:08:40,710 We'll also listen for when the prompt is triggered. 135 00:08:41,220 --> 00:08:44,070 It'll also tell us what player triggered the prompt. 136 00:08:44,070 --> 00:08:47,340 So we'll just print out triggered. 137 00:08:48,840 --> 00:08:51,090 And it was triggered by this player. 138 00:08:51,090 --> 00:08:56,580 We'll get their name and then we can go ahead and also listen for when the prompt is displayed on the 139 00:08:56,580 --> 00:08:56,940 screen. 140 00:08:56,940 --> 00:08:58,650 So prompt shown. 141 00:09:01,310 --> 00:09:03,350 We'll just print shown. 142 00:09:04,860 --> 00:09:06,570 And then last but not least, we'll listen. 143 00:09:06,570 --> 00:09:11,280 For when the prompt becomes hidden, we'll connect a function to that and print out. 144 00:09:12,190 --> 00:09:13,060 Hidden. 145 00:09:13,820 --> 00:09:16,430 Okay, let's go ahead and play test the game. 146 00:09:17,250 --> 00:09:19,920 If I go and walk over to this prompts, there we go. 147 00:09:19,920 --> 00:09:24,060 We get printed out, shown, and then if I walk away, it becomes hidden. 148 00:09:24,580 --> 00:09:25,720 Then it's shown again. 149 00:09:25,720 --> 00:09:28,870 If I hold down, we should see hold begin. 150 00:09:28,870 --> 00:09:29,860 So we'll hold down. 151 00:09:29,890 --> 00:09:30,310 See? 152 00:09:30,460 --> 00:09:31,150 There we go. 153 00:09:31,150 --> 00:09:33,430 It started and then my name printed out. 154 00:09:33,430 --> 00:09:36,520 And then we ended the hold because it got triggered. 155 00:09:36,520 --> 00:09:39,880 So it printed end and it also printed triggered. 156 00:09:40,120 --> 00:09:46,630 Now one issue you might see with this is let's say you have dozens or hundreds of proximity prompts 157 00:09:46,630 --> 00:09:51,670 and your game, you don't want to have to make a references to every single one of those proximity prompts 158 00:09:51,670 --> 00:09:57,190 to be able to listen for maybe when it's shown or it's hidden or when it's triggered and whatnot. 159 00:09:57,190 --> 00:10:02,770 So Roblox has provided a service for us called the Proximity Prompt Service. 160 00:10:02,770 --> 00:10:10,000 So we'll call this Proximity prompt service is equal to game jet service, proximity Prompt service. 161 00:10:10,000 --> 00:10:15,670 And this service has a ton of useful events that are very similar to the events that are inside of a 162 00:10:15,670 --> 00:10:16,660 proximity prompt. 163 00:10:16,660 --> 00:10:23,200 However, these events will fire any time a prompt is triggered or displayed or held down in your game. 164 00:10:23,200 --> 00:10:24,880 So we have different events. 165 00:10:24,880 --> 00:10:30,970 For example, prompt Buttonholed began triggers when the player begins holding down a proximity prompt, 166 00:10:30,970 --> 00:10:38,650 and if we connect to this event, it'll give us what prompt is being held down and the player that triggered 167 00:10:38,650 --> 00:10:39,070 it. 168 00:10:39,070 --> 00:10:44,560 We can do the same thing for when a prompt ends, and it'll give us the proximity prompt and the player 169 00:10:45,190 --> 00:10:47,650 we can listen for when a prompt is triggered. 170 00:10:47,650 --> 00:10:50,020 And again, it'll give us that prompt and the player. 171 00:10:50,590 --> 00:10:55,990 And then specifically for the client side, we can listen for when any prompt in our game is shown, 172 00:10:55,990 --> 00:10:59,200 or when any of the prompts in our game are hidden. 173 00:10:59,200 --> 00:11:03,700 And then we're also able to listen for when the trigger ends on a proximity prompt. 174 00:11:03,700 --> 00:11:06,130 And I believe we can do that for regular. 175 00:11:06,130 --> 00:11:08,830 Yeah, we could do that for regular proximity prompts as well. 176 00:11:08,830 --> 00:11:15,430 So it says triggers when the key button is released for longer events when the user is required to hold 177 00:11:15,430 --> 00:11:16,390 down the button. 178 00:11:16,390 --> 00:11:21,580 So if you remember earlier with my proximity prompt that appears right here, I have to hold it down. 179 00:11:21,580 --> 00:11:25,210 And then if I keep holding it down, it's going to keep the button triggered. 180 00:11:25,210 --> 00:11:31,750 It isn't until I release my finger off of that key where the trigger ended event will fire. 181 00:11:32,200 --> 00:11:35,380 The proximity prompts are very useful to use in your games. 182 00:11:35,380 --> 00:11:40,360 Most of the time, you're just going to be using them to listen for when a player interacts with a specific 183 00:11:40,360 --> 00:11:41,860 thing in your game. 184 00:11:41,860 --> 00:11:47,980 Of course, you can create more customized proximity prompts by creating a custom GUI, but that's a 185 00:11:47,980 --> 00:11:51,880 little bit more advanced than what we're going to focus on with this video. 186 00:11:52,120 --> 00:11:55,960 Other than that, that was just my brief overview of proximity prompts. 187 00:11:55,960 --> 00:11:57,610 That's all for me in this lecture. 188 00:11:57,610 --> 00:12:00,910 I hope you enjoyed and I'll see you in the next one.